package com.imti.mall.product.mapper;

import com.imti.mall.model.pms.pojo.PmsBrand;
import com.imti.mall.model.pms.pojo.PmsProductAttributeCategory;
import com.imti.mall.model.pms.pojo.PmsProductAttributeValue;
import com.imti.mall.model.pms.pojo.PmsProductCategory;
import com.imti.mall.model.pms.vo.PmsBrandVo;
import org.apache.ibatis.jdbc.SQL;

import java.util.Map;

/**
 * ClassName: PmsBrandCategoryDynaSqlProvider
 * Description:
 * date: 2022/9/13 11:21
 *
 * @author: youhun
 * @version:
 * @since JDK 1.8
 */
public class PmsBrandCategoryDynaSqlProvider {

    /**
     * 修改商品品牌表sql语句的方法
     * @param pmsBrand
     * @return
     */
    public String UpdatePmsBrand(final PmsBrandVo pmsBrand){
        return new SQL(){
            {
                UPDATE(" `pms_brand` ");
                if(pmsBrand.getName()!=null){
                    SET(" name=#{name} ");
                }
                if(pmsBrand.getFirstLetter()!=null){
                    SET(" first_letter=#{firstLetter} ");
                }
                if(pmsBrand.getSort()!=null){
                    SET(" sort=#{sort} ");
                }
                if(pmsBrand.getFactoryStatus()!=null){
                    SET(" factory_status=#{factoryStatus} ");
                }
                if(pmsBrand.getShowStatus()!=null){
                    SET(" show_status=#{showStatus} ");
                }
                if(pmsBrand.getProductCount()!=null){
                    SET(" product_count=#{productCount} ");
                }
                if(pmsBrand.getProductCommentCount()!=null){
                    SET(" product_comment_count=#{productCommentCount} ");
                }
                if(pmsBrand.getLogo()!=null){
                    SET(" logo=#{logo} ");
                }
                if(pmsBrand.getBigPic()!=null){
                    SET(" big_pic=#{bigPic} ");
                }
                if(pmsBrand.getBrandStory()!=null){
                    SET(" brand_story=#{brandStory} ");
                }
                WHERE(" id=#{id} ");
            }
        }.toString();
    }
    /**
     * 动态查询商品品牌表的
     * @param pmsBrand
     * @return
     */
    public String findPmsBrand(PmsBrand pmsBrand){
        return new SQL(){
            {
                SELECT(" id,NAME,first_letter,sort,factory_status,show_status,show_status,product_count,product_comment_count,logo,big_pic,brand_story ");
                FROM(" pms_brand ");
                StringBuffer sb=new StringBuffer();
                if(pmsBrand!=null) {
                    //按照是否为品牌制造商查找
                    if (pmsBrand.getFactoryStatus()!= null) {
                        sb.append(" and  factory_status=#{factoryStatus}");
                    }
                    //根据上级分类的编号进行查询
                    if (pmsBrand.getName() != null) {
                        sb.append(" and name  LIKE concat('%',#{name},'%')");
                    }
                }
                WHERE(" 1=1 "+sb.toString());
            }
        }.toString();
    }


    /**
     * 查询总条数
     * @param pmsBrand
     * @return
     */
    public String getPmsBrand(PmsBrand pmsBrand){
        return new SQL(){
            {
                SELECT(" count(*) ");
                FROM(" pms_brand ");
                StringBuffer sb=new StringBuffer();
                if(pmsBrand!=null) {
                    //按照是否为品牌制造商查找
                    if (pmsBrand.getFactoryStatus()!= null) {
                        sb.append(" and  factory_status=#{factoryStatus}");
                    }
                    //根据上级分类的编号进行查询
                    if (pmsBrand.getName() != null) {
                        sb.append(" and name  LIKE concat('%',#{name},'%')");
                    }
                }
                WHERE(" 1=1 "+sb.toString());
            }
        }.toString();
    }


    /**
     * 修改商品属性值表的动态sql
     */
    public String updatePmsProductAttributeValue(final PmsProductAttributeValue pmsProductAttributeValue){
        return new SQL(){
            {
                UPDATE(" `pms_product_attribute_value` ");
                if(pmsProductAttributeValue.getProductAttributeId()!=null){
                    SET(" product_id=#{productAttributeId} ");
                }
                if(pmsProductAttributeValue.getProductAttributeId()!=null){
                    SET(" product_attribute_id=#{productAttributeId} ");
                }
                if(pmsProductAttributeValue.getValue()!=null){
                    SET(" value=#{value} ");
                }
                WHERE(" id=#{id} ");
            }
        }.toString();
    }

    /**
     * 查询总条数
     * @param pmsProductAttributeValue
     * @return
     */
    public String findPmsProductAttributeValue(final PmsProductAttributeValue pmsProductAttributeValue){
        return new SQL(){
            {
                SELECT(" id,product_id,product_attribute_id,value ");
                FROM(" pms_product_attribute_value ");
                StringBuffer sb=new StringBuffer();
                if(pmsProductAttributeValue!=null) {
                    //按照是否为品牌制造商查找
                    if (pmsProductAttributeValue.getProductId()!= null) {
                        sb.append(" and  product_id=#{productId}");
                    }
                    if (pmsProductAttributeValue.getProductAttributeId()!= null) {
                        sb.append(" and  product_attribute_id=#{productAttributeId}");
                    }
                    //根据上级分类的编号进行查询
                    if (pmsProductAttributeValue.getValue()!= null) {
                        sb.append(" and value  LIKE concat('%',#{value},'%')");
                    }
                }
                WHERE(" 1=1 "+sb.toString());
            }
        }.toString();
    }
}
